﻿using Infrastructure.Tool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WsdShop.IService;
using WsdShop.Model.Enum;
using WsdShop.Model.SearchModels;

namespace Admin.Controllers
{
    public class ReportController : BaseController
    {
        protected IReportService reportservice;
        public ReportController(IUserInfoService s, IReportService _reportservice) : base(s)
        {
            reportservice = _reportservice;
        }
        // GET: Report
        public void GetDeliverGoods(string orderno, string begintime, string endtime, int ordersendstatus, int ordertype)
        {
            var dt = reportservice.GetDeliverGoods(orderno, begintime, endtime, ordersendstatus,ordertype);
            ExcelTool.ExportExcel(ReportType.发货单, dt, "");

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderno">订单号</param>
        /// <param name="begintime"></param>
        /// <param name="endtime"></param>
        /// <param name="orderstatus">订单状态</param>
        /// <param name="paystatus">支付状态</param>
        /// <param name="sendstatus">发货状态</param>
        public void GetOrder(string orderno, string begintime, string endtime, int orderstatus, int paystatus, int sendstatus,int ordertype)
        {
            var dt = reportservice.GetOrder(orderno, begintime, endtime, orderstatus, paystatus, sendstatus, ordertype);
            ExcelTool.ExportExcel(ReportType.订单表, dt, "订单");
        }


        public void GetRerurnGoods(string orderno, string begintime, string endtime, int satus, int returntype)
        {
            var dt = reportservice.GetRerurnGoods(orderno, begintime, endtime, satus, returntype);
            ExcelTool.ExportExcel(ReportType.退货单, dt, "退货单");
        }

        public void ProductManage(string Keywords, string FirstCategoryIdParm, string SecondCategoryIdParm, string IsDisplayParm)
        {
            ProductSearchModel m = new ProductSearchModel();
            m.Keywords = Keywords;
            if (FirstCategoryIdParm != "undefined")
            {
                m.FirstCategoryIdParm = Convert.ToInt32(FirstCategoryIdParm);
            }
            else
            {
                m.FirstCategoryIdParm = -1;
            }
            if (SecondCategoryIdParm != "undefined")
            {
                m.SecondCategoryIdParm = Convert.ToInt32(SecondCategoryIdParm);
            }
            else
            {
                m.SecondCategoryIdParm = -1;
            }

            if (IsDisplayParm != "undefined")
            {
                m.IsDisplayParm = Convert.ToInt32(IsDisplayParm);
            }
            else
            {
                m.IsDisplayParm = -1;
            }
            var dt = reportservice.ProductManage(m);
            ExcelTool.ExportExcel(ReportType.商品表, dt, "商品");
        }

        public void GetMemberList(string Keywords,int MemberLevel)
        {

            MemberSearchModel search = new MemberSearchModel();
            search.Keywords = Keywords;
            search.MemberLevel = MemberLevel;
            var dt = reportservice.GetMemberList(search);
            ExcelTool.ExportExcel(ReportType.会员, dt, "");
        }
    }
}